package com.fingard.dsp.web.page.receipt;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;

import com.fingard.FGBiz;
import com.fingard.common.utils.json.JSONUtils;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.web.page.PageBase;

public class DeleteMapData extends PageBase {
	@Override
    public void pageLoad() throws Exception {
        httpContext.response.isRtnBytes = false;
        httpContext.response.setContentType("txt", "");
        StringBuilder sbJson = new StringBuilder();
        String respCode = "";
        String respInfo = "";
        Connection conn = null;
        try {
            int delDateFrom = 0;
            int delDateEnd = 0;
            String delAct = "";
            String reqJson = httpContext.request.httpReceiver.getReqBodyContent();
            HashMap<String, String> reqParams = JSONUtils.json2Map(reqJson);
            if (reqParams.containsKey("delDateFrom") && reqParams.get("delDateFrom").length() > 0) {
            	delDateFrom = Integer.parseInt(reqParams.get("delDateFrom"));
            }
            if (reqParams.containsKey("delDateEnd") && reqParams.get("delDateEnd").length() > 0) {
            	delDateEnd = Integer.parseInt(reqParams.get("delDateEnd"));
            }
            if (reqParams.containsKey("delAct")) {
            	delAct = reqParams.get("delAct");
            }
            ArrayList<Object> paramArray = new ArrayList<Object>();
            String sql = "delete from RECEIPTMAPPING where BUSDATE>=? and BUSDATE<=? and OWNACT=?";
            if (delDateFrom > 0 && delDateEnd > 0 && delAct.length() > 0) {
            	paramArray.add(delDateFrom);
            	paramArray.add(delDateEnd);
            	paramArray.add(delAct);
            	Object[] delParams = null;
            	delParams = paramArray.toArray();
            	conn = FGBiz.getLocalDbConn();
            	int rowAffs = JDBCHelper.update(conn, sql, delParams);
            	respCode = "0";
            	respInfo = "执行成功，影响行数："+rowAffs;
            }else{
            	respCode = "-1";
            	if(delDateFrom<=0){
            		respInfo = "开始日期不能为空；";
            	}
            	if(delDateEnd<=0){
            		respInfo += "结束日期不能为空；";
            	}
            	if(delAct.length()<=0){
            		respInfo += "账号不能为空";
            	}
            }
            
        } catch (Exception ex) {
            respCode = "-1";
            respInfo = ex.toString();
            FGBiz.limitMsg.exception(this.getClass().getSimpleName(), ex);
        } finally {
            if (conn != null) {
                conn.close();
            }
        }

        sbJson.append("{");
        sbJson.append("\"respCode\":" + "\"" + respCode + "\",");
        sbJson.append("\"respInfo\":" + "\"" + respInfo + "\"");
        sbJson.append("}");
        httpContext.response.respMsg = sbJson.toString();
    }
}
